package org.rcy.framework.api.cacheable;

public class CacheKeyStrategy {
    public static final String COLON = "_";

    public CacheKeyStrategy() {
    }

    public static String getCacheKey(Object id, String... prefixs) {
        return getRedisKey(id, prefixs);
    }

    public static String getRedisKey(Object id, String... prefixs) {
        StringBuilder builder = new StringBuilder();
        String[] prefixsArray = prefixs;
        int prefixsLength = prefixs.length;

        for(int index = 0; index < prefixsLength ; ++index) {
            String prefix = prefixsArray[index];
            if (prefix != null) {
                builder.append(prefix).append(COLON);
            }
        }

        return builder.append(String.valueOf(id)).toString();
    }
}